﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppManage.Data.Items;

namespace AppManage.EntityFramework.Mapping
{
    public class ItemMap : EntityTypeConfiguration<Item>
    {
        public ItemMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.ItemName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ControlName)
                .HasMaxLength(100);

            this.Property(t => t.Icon)
                .HasMaxLength(100);

            this.Property(t => t.Description)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Items");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ItemName).HasColumnName("ItemName");
            this.Property(t => t.ParentItemId).HasColumnName("ParentItemId");
            this.Property(t => t.FunctionId).HasColumnName("FunctionId");
            this.Property(t => t.ControlName).HasColumnName("ControlName");
            this.Property(t => t.Icon).HasColumnName("Icon");
            this.Property(t => t.IsActive).HasColumnName("IsActive");
            this.Property(t => t.Description).HasColumnName("Description");

            //Relateships
            this.HasOptional(t => t.Function)
                .WithMany(t => t.Items)
                .HasForeignKey(t => t.FunctionId);
        }
    }
}
